<template>
  <div class="loginStyle" style="
display: block;
 ">
    <el-card class="box-card"
             style="width: 500px;height: 450px;float: right;position: absolute;right: 200px;top: 200px;background: lightskyblue">
      <div slot="header" class="clearfix">
        <span style="font-size: 40px">正经人听的音乐</span>
      </div>
      <el-form :model="user" :rules="registerRule" ref="loginForm" class="demo-ruleForm" style="">
        <el-form-item label="姓名" prop="name" style="position: absolute;left: 90px;top: 130px">
          <el-input v-model="user.name" style="width: 250px;position: absolute;left: 60px;"></el-input>
        </el-form-item>
        <el-form-item label="账号" prop="account" style="position: absolute;left: 90px;top: 190px">
          <el-input v-model.number="user.account" style="width: 250px;position: absolute;left: 60px"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" style="position: absolute;left: 90px;top: 250px">
          <el-input v-model="user.password" style="width: 250px;position: absolute;left: 60px;"></el-input>
        </el-form-item>
      </el-form>
      <br>
      <br>
      <!--     按钮-->
      <el-button @click="register" type="success" plain style="width: 100px;position: absolute;top: 330px;left: 160px;">
        注册
      </el-button>
      <el-button @click="$router.push('/login')" type="success" plain
                 style="width: 100px;position: absolute;top: 330px;left: 270px;">去登陆
      </el-button>
    </el-card>
  </div>
</template>
<script>
export default {
  name: "login",

  data() {
    return {
      user: {},
      registerRule: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'},
          {min: 2, max: 30, message: "长度在 2 到 30 个字符", trigger: "blur"}
        ],
        account: [
          {required: true, message: '请输入账号', trigger: 'blur'},
          {type: 'number', message: '账号必须为数字'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {

    register() {
      this.$axios.post("/api/user/register", this.user).then(res => {
        console.log(res);
        if (res.data.status === 1) {
          localStorage.setItem("TOKEN", res.data.data.token);
          this.$message.success('注册成功');
        } else {
          this.$message.error('账号或密码不正确');
        }
      })
    }
  },
}
</script>

<style scoped>
.loginStyle {
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url('../img/c5f.gif');
  background-size: 100% 100%;
  height: 100%;
  background-size: cover;
}
</style>
